home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / lang / nrcobol_1e.lha / NRCOBOL1e / WB13 / Extra / NRCOBOL.REXX < prev    next >
OS/2 REXX Batch file  |  1998-09-22  |  9KB  |  315 lines

  1.  
  2. /*
  3.    Macro Arexx per compilare il Programma Cobol
  4.    Se il file non è stato salvato verrà richiesto di farlo
  5. */
  6.  
  7. Options Results
  8.  
  9. Call AddLib('rexxsupport.library',0,-30,0)
  10. Call AddLib('rexxtricks.library',0,-30,0)
  11.  
  12. Operazione      = UPPER(Arg(1))
  13.  
  14. Ret            = '0A'x
  15. Port           = 'COBOL'
  16.  
  17. Est.Sorgente   = 'COB'
  18. Est.Exe        = 'INT'
  19. Est.Lista      = 'LST'
  20. Est.Change     = 'CNG'
  21. Est.LastComp   = 'RES'
  22. Est.LastErr    = 'ERR'
  23.  
  24. Msg.NoPort     = 'La porta di comunicazione' Port 'Non esiste'
  25. Msg.ErrNoSave  = 'Il file deve essere salvato con un nome'
  26. Msg.ErrEst     = 'Il file deve avere estensione' Est.Sorgente
  27. Msg.ErrNoLista = 'Il file listato non esiste'
  28. Msg.ErrLista   = 'L''opzione di creazione del file' || RET ||'listato deve essere attivata'
  29. Msg.Comp       = 'Compilazione del file'
  30. Msg.Wait       = '-- Attendere Prego --'
  31. Msg.NoErr      = 'Nessun errore'
  32. Msg.NoNextErr  = 'Nessun altro errore'
  33. Msg.Exe        = 'Eseguo il file'
  34. Msg.Config     = 'Configurazione: (S) Salva - (U) Usa - (C) Cancella'
  35. Msg.ErrSaveCfg = 'Impossibile salvare le impostazioni'
  36. Msg.Save       = 'Vuoi che il file sorgente' Ret 'venga salvato automaticamente?'
  37. Msg.Lista      = 'Vuoi che il compilatore generi' Ret 'il listato del file che sta compilando'
  38. Msg.Debug      = 'Vuoi che il compilatore generi' Ret 'il file di debug'
  39.  
  40. NRCOBOL        = 'Lavoro:Programmazione/Cobol/NrCobol'
  41. RUNCOB         = 'Lavoro:Programmazione/Cobol/RunCob'
  42.  
  43. Modifiche      = 0
  44.  
  45. CED.RESTNAME       = 21
  46. CED.FILENAME       = 19
  47. CED.NUMCHANGES     = 18
  48. CED.CURSORLINE     = 47
  49.  
  50. /* DEFAULT SETUP */
  51.  
  52. Cfg.Nome          = 'Cobol.prefs'
  53. Cfg.Salvataggio   = 0
  54. Cfg.Lista         = 1
  55. Cfg.Debug         = 1
  56.  
  57.  
  58. /* MAIN */
  59.  
  60. Call Carica_Configurazione
  61.  
  62. If Port ~= Left(ADDRESS(),Length(Port)) Then
  63.    Say Msg.NoPort
  64.  
  65. Nome.Sorgente = Ottieni_Nome_File(CED.RESTNAME)
  66. If Nome.Sorgente = '' Then
  67.    Do
  68.       'Save As'
  69.       If RESULT = 0 Then
  70.          Do
  71.             'Okay1' Msg.ErrNoSave
  72.             CALL Uscita(0)
  73.          End
  74.   End
  75. Else
  76.    Do
  77.       'Status' CED.NUMCHANGES
  78.       Modifiche = Result
  79.       If Cfg.Salvataggio = 1 & Modifiche ~= 0 Then
  80.          'Save'
  81.    End
  82.  
  83. Nome.Sorgente = Ottieni_Nome_File(CED.FILENAME)
  84. if UPPER(SuffixPart(Nome.Sorgente)) ~= Est.Sorgente Then
  85.    Do
  86.       'Okay1' Msg.ErrEst
  87.       Call Uscita(0)
  88.    End
  89.  
  90. Nome.File     = Strip(FilePart(MakeSuffix(Nome.Sorgente,'',R)),'T','.')
  91. Nome.Change   = Nome.File || Est.Change
  92. Nome.LastComp = Nome.File || Est.LastComp
  93. Nome.LastErr  = Nome.File || Est.LastErr
  94. Nome.Exe      = MakeSuffix(Nome.Sorgente, Est.Exe,'R')
  95. Nome.Lista    = MakeSuffix(Nome.Sorgente, Est.Lista,'R')
  96.  
  97. SELECT
  98.    When Operazione   = 'COMPILA'   Then
  99.       CALL Compila
  100.    When Operazione   = 'ESEGUI'    Then
  101.       CALL Esegui
  102.    When Operazione   = 'CONFIGURA' Then
  103.       CALL Configura
  104.    When Operazione   = 'ERRORI'    Then
  105.       CALL Errori
  106.    OtherWise
  107.       NOP
  108. End
  109.  
  110. CALL Uscita(0)
  111.  
  112. /* END MAIN */
  113.  
  114. Compila: Procedure Expose NRCOBOL RUNCOBOL Nome. Msg. Cfg. Ret Modifiche
  115.    'DM' Msg.Comp Nome.Sorgente Msg.Wait
  116.    If Cfg.Lista = 1 Then Opzioni = '-L'
  117.    If Cfg.Debug = 1 Then Opzioni = Opzioni '-D'
  118.    Opzioni = Opzioni '>' 'T:' || Nome.File
  119.    CALL Compilazione(Nome.Sorgente, Opzioni)
  120.    Risultato = VisualizzaRisultati('T:' || Nome.File)
  121.    CALL SetEnv(Nome.LastComp, Risultato)
  122.    CALL SetEnv(Nome.LastErr, 4)
  123.    'DM'
  124. Return Risultato
  125.  
  126. Esegui: Procedure Expose NRCOBOL RUNCOBOL Nome. Msg. Cfg. Ret Modifiche
  127.    Run = GetEnv(Nome.LastComp)
  128.    If Run = '' Then
  129.       Run = 1
  130.    ModifichePrecedenti    = GetEnv(Nome.Change)
  131.    If ModifichePrecedenti = '' Then
  132.       ModifichePrecedenti = Modifiche
  133.    CALL SetEnv(Nome.Change, Modifiche)
  134.    If ~Newer(Nome.Sorgente, Nome.Exe) | Modifiche ~= ModifichePrecedenti | Run = 0 Then
  135.       Run = Compila()
  136.    If Run = 1 Then
  137.        Do
  138.           'DM' Msg.Exe Nome.Exe
  139.           CALL Esecuzione(Nome.Exe)
  140.        End
  141.   'Dm'
  142. Return Run
  143.  
  144. Configura: Procedure Expose Ret Cfg. Msg.
  145.     'Okay2' Msg.Save;    Salvataggio = Result
  146.     'Okay2' Msg.Lista;   Lista       = Result
  147.     'Okay2' Msg.Debug;   Debug       = Result
  148.     Impostazioni = Salvataggio Lista Debug
  149.     Continua = 1
  150.     Do While Continua = 1
  151.        'DM' Msg.Config
  152.        Tasto = -1
  153.        Do Until Tasto ~= -1
  154.           'LASTKEY'
  155.           Tasto = RESULT
  156.        End
  157.        Key = Word( Tasto, 1)
  158.        SELECT
  159.           When Key = 33 Then CALL Salva
  160.           When Key = 22 Then CALL Usa
  161.           When Key = 51 Then Continua = 0
  162.           OtherWise NOP
  163.        End
  164.     End
  165.     'DM'
  166. Return
  167.  
  168. Errori: Procedure Expose Nome. Msg. Cfg. CED. RET
  169.    Res      = GetEnv(Nome.LastComp)
  170.    LastLine = GetEnv(Nome.LastErr)
  171.    If LastLine  = '' Then LastLine = 4
  172.    Select
  173.        When Cfg.Lista = 0       Then Messaggio = Msg.ErrLista
  174.        When Res       = 1       Then Messaggio = Msg.NoErr
  175.        When ~Exists(Nome.Lista) Then Messaggio = Msg.ErrNoLista
  176.        OtherWise
  177.           Fine = 0
  178.           Do Until Fine = 1
  179.              Line = SearchPattern(Nome.Lista, 'LINE', LastLine, 'L', 'N')
  180.              If Line ~= -1 Then
  181.                 Do
  182.                    Parse Var Result Dummy 'Line' Numero Errore
  183.                    If DataType(Numero,'N') & Dummy ='' Then
  184.                       Do
  185.                          Messaggio = 'Errore alla Linea:' Numero || Ret || 'Causa:' Errore
  186.                          LL Numero
  187.                          'Dm' Errore
  188.                          SetEnv(Nome.LastErr, Line + 1)
  189.                          Fine = 1
  190.                       End
  191.                    Else
  192.                       LastLine = Line + 1
  193.                 End
  194.              Else
  195.                 Do
  196.                    Messaggio = Msg.NoNextErr
  197.                    Fine = 1
  198.                 End
  199.           End
  200.    End
  201.    'Okay1' Messaggio
  202. Return
  203.  
  204. Salva:
  205.    If ~Open(Handle,'ENVARC:' || Cfg.Nome,'W') Then
  206.        'Okay1' Msg.ErrSaveCfg
  207.     Else
  208.        Writeln(Handle, Impostazioni)
  209. Usa:
  210.    CALL SetEnv(Cfg.Nome, Impostazioni)
  211.    Continua = 0
  212. Return
  213.  
  214. Compilazione: Procedure Expose NRCOBOL
  215.    ADDRESS COMMAND NRCOBOL '"' || Arg(1) || '"' Arg(2)
  216. Return
  217.  
  218. Esecuzione: Procedure Expose RUNCOB
  219.    ADDRESS COMMAND RUNCOB '"' || Arg(1) || '"'
  220. Return
  221.  
  222. Ottieni_Nome_File: Procedure
  223.    'Status' ARG(1)
  224. Return RESULT
  225.  
  226. Newer: Procedure
  227.    NomeFile1 = ARG(1)
  228.    NomeFile2 = ARG(2)
  229.    Parse Value Statef(NomeFile1) With . . . . GiorniFile1 Minuti CinquSec .
  230.    SecondiFile1 = ( Minuti * 60 ) + ( CinquSec / 50 )
  231.    If Exists(NomeFile2) Then
  232.       Do
  233.          Parse Value Statef(NomeFile2) With . . . . GiorniFile2 Minuti CinquSec .
  234.          SecondiFile2 = ( Minuti * 60 ) + ( CinquSec / 50 )
  235.          If GiorniFile1 <= GiorniFile2 & SecondiFile1 < SecondiFile2 Then
  236.             Return 1
  237.       End
  238. Return 0
  239.  
  240. Carica_Configurazione: Procedure Expose Cfg.
  241.    Configurazione = GetEnv(Cfg.Nome)
  242.    If Configurazione ~= '' Then
  243.        Parse Var Configurazione Cfg.Salvataggio Cfg.Lista Cfg.Debug
  244. Return
  245.  
  246. VisualizzaRisultati: PROCEDURE Expose RET
  247.    Ok            = 1
  248.    TempFile      = ARG(1)
  249.    Intestazione  =  'NRCOBOL V1.0d - cHArRiOTt97-98(c)'
  250.    Pattern.0     = 5
  251.    Pattern.1     = 'IDENTIFICATION DIVISION'
  252.    Pattern.2     = 'ENVIRONMENT DIVISION'
  253.    Pattern.3     = 'DATA DIVISION'
  254.    Pattern.4     = 'PROCEDURE DIVISION'
  255.    Pattern.5     = 'Ending at'
  256.    Adj.1         = 27
  257.    Adj.2         = 28
  258.    Adj.3         = 34
  259.    Adj.4         = 29
  260.    Adj.5         = 0
  261.    LCurr         = 1
  262.    Do Pat = 1 To Pattern.0
  263.        LPrec = SearchPattern(TempFile, Pattern.Pat, LCurr, 'L', 'N')
  264.        IF LPrec = -1  Then
  265.           Do
  266.              LCurr = -1
  267.              LPrec = 0
  268.           End
  269.        Else If Pat < Pattern.0 Then
  270.           LCurr = SearchPattern(TempFile, Pattern.Pat, LPrec + 1, 'L', 'N')
  271.        Else
  272.           LCurr = LPrec
  273.        If LCurr ~= -1 Then
  274.           Do
  275.              PARSE Var Result (Pattern.Pat) Risultato.Pat
  276.              Risultato.Pat = Traduci(Strip(Risultato.Pat,'B','. '))
  277.           End
  278.        Else
  279.           Do
  280.              LCurr = LPrec + 1
  281.              Risultato.Pat = 'omessa'
  282.              Ok = 0
  283.           End
  284.    End
  285.    Messaggio = Intestazione
  286.    Do Pat = 1 For Pattern.0
  287.       Messaggio = Messaggio || Copies(Ret,2) || Left(Pattern.Pat,Adj.pat,'.') || Risultato.Pat
  288.    End
  289.    'Okay1' Me